<?php

/*
+--------------------------------------------------------------------------
|   Invision Power Board
|   =============================================
|   by Matthew Mecham
|   (c) 2001 - 2006 Invision Power Services, Inc.
|   
|   =============================================
|   
|   
+---------------------------------------------------------------------------
|   > $Date: 2009-05-10 11:35:56 -0400 (Sun, 10 May 2009) $
|   > $Revision: 1 $
|   > $Author: BabyWolf $
+---------------------------------------------------------------------------
|
|   > Multi Site functions
|   > Module written by BabyWolf
|   > Date started: 10th May 2009
|
|	> Module Version Number: 1.0.0
|   > DBA Checked: 
+--------------------------------------------------------------------------
*/

if ( ! defined( 'IN_ACP' ) )
{
	print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'admin.php'.";
	exit();
}

class ad_locations {

	function auto_run()
	{
		$this->ipsclass->forums->forums_init();
		
		require ROOT_PATH.'sources/lib/admin_forum_functions.php';
		
		$this->forumfunc = new admin_forum_functions();
		$this->forumfunc->ipsclass =& $this->ipsclass;
		
		$this->ipsclass->admin->nav[]       = array( "{$this->ipsclass->form_code}", "Shop Management" );

		//-----------------------------------------
		// Load template
		//-----------------------------------------

		$this->html = $this->ipsclass->acp_load_template( 'cp_skin_shops' );

		

		//-----------------------------------------

		$this->ipsclass->DB->sql_get_version();

		$this->true_version  = $this->ipsclass->DB->true_version;
		$this->mysql_version = $this->ipsclass->DB->mysql_version;

		switch($this->ipsclass->input['code'])
		{
			// Category functions
			
			case 'location_delete':
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':remove' );
				$this->location_delete();
				$this->country_form();
				break;
			case 'sites_showedit':
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
				$this->site_form('edit');
				break;
				
			case 'country_new':
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );
				$this->country_form('add');
				break;

			case 'country_add':
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );
				$this->country_save('add');
				break;
			case 'country_edit':
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
				$this->country_save('edit');
				break;
			case 'country_showedit':
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
				$this->country_form_edit();
				break;
			case 'city_show':
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':' );
				$this->city_show();
				break;
			case 'city_new':
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );
				$this->city_form('add');
				break;
			case 'city_add':
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );
				$this->city_save();
				$this->city_show();
				break;
			case 'city_edit':
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
				$this->city_save('countryid','edit');
				$this->city_show();
				break;
			case 'city_showedit':
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
				$this->city_form('edit');
				break;
			case 'city_delete':
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':remove' );
				$this->location_delete();
				$this->city_show();
				break;
			case 'district_view':
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':' );
				$this->district_view();
				break;
			case 'district_new':
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );
				$this->district_form();
				break;
			case 'district_add':
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );
				$this->city_save('cityid');
				$this->district_view();
				break;
			case 'district_showedit':
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
				$this->district_form('edit');
				break;
			case 'district_edit':
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
				$this->city_save('cityid','edit');
				$this->district_view();
				break;
			case 'district_delete':
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
				$this->location_delete();
				$this->district_view();
				break;
			//-----------------------------------------
			default:
				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':' );
				$this->country_form();
				break;
		}

	}

	//-----------------------------------------
	//
	// Delete setting group
	//
	//-----------------------------------------

	function location_delete()
	{
		if ( $this->ipsclass->input['id'] )
		{
			$this->ipsclass->DB->simple_exec_query( array( 'delete' => 'location', 'where' => 'location_id='.intval($this->ipsclass->input['id']) ) );

			$this->ipsclass->main_msg = "Location Removed";
		}

	}

	//-----------------------------------------
	// Category Save Form
	//-----------------------------------------

	function country_save($type='add')
	{
		//-----------------------------------------
		// INIT
		//-----------------------------------------

		$location_name = $this->ipsclass->input['locationName'];

		//-----------------------------------------
		// Check...
		//-----------------------------------------

		if ( ! $location_name )
		{
			$this->ipsclass->main_msg = "You must enter location name.";
			$this->country_form();
			return;
		}
		
		
		$location_skin_id = $this->ipsclass->input['locationSkin'];
		$location_forum_ids = serialize($this->ipsclass->input['locationForums']);
		
		//-----------------------------------------
		// check...
		//-----------------------------------------

		$array = array( 'location_name' 		=> $location_name,
						'location_level' 		=> $this->ipsclass->input['level'],
						'location_parent' 		=> $this->ipsclass->input['parent'],
					 );


		if ( $type == 'add' )
		{
			$this->ipsclass->DB->do_insert( 'location', $array );
			$this->ipsclass->main_msg = 'New location Added';
		}
		else
		{
			$this->ipsclass->DB->do_update( 'location', $array, 'location_id='.intval($this->ipsclass->input['id']) );
			$this->ipsclass->main_msg = 'New location Edited';
		}

		$this->country_form();
	}


	function country_form_edit(){
		$location = $this->ipsclass->DB->simple_exec_query( array( 'select' => '*', 'from' => 'location', 'where' => 'location_id='.intval($this->ipsclass->input['id']) ) );

		if ( ! $location['location_id']) {
			$this->ipsclass->main_msg = "No ID was passed, please try again.";
			$this->country_form();
		}

		$formcode = 'country_edit';
		$title    = "Edit Country <u>".$location['location_name']."</u>";
		$button   = "Edit Country";
		$this->ipsclass->admin->page_detail = '&nbsp;';
		$this->ipsclass->admin->page_title  = $title;

		//-----------------------------------------
		// start form
		//-----------------------------------------

		$this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'code'   , $formcode ),
																			 2 => array( 'act'    , 'locations'      ),
																			 3 => array( 'id'     , $this->ipsclass->input['id'] ),
																			 4 => array( 'parent'     , $location['location_parent'] ),
																			 5 => array( 'level'     , $location['location_level'] ),
																			 6 => array( 'section', 'content' ),
																	)      );

		//-----------------------------------------
		// start table
		//-----------------------------------------

		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "40%" );
		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "60%" );

		//-----------------------------------------
		// um..
		//-----------------------------------------

		$this->ipsclass->html .= $this->ipsclass->adskin->start_table( $title );
												 		    	
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Country Name</b><div style='color:gray'>Example: Việt Nam</div>" ,
												  			   $this->ipsclass->adskin->form_input( 'locationName',$location['location_name'] )
										 		    	)      );
		
		$this->ipsclass->html .= $this->ipsclass->adskin->end_form( $button );

		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();

		$this->ipsclass->admin->output();
	}
	
	function country_form()
	{
		
		$this->ipsclass->admin->page_title  = "Location management";
		$this->ipsclass->admin->page_detail = "This section contains all the functions to manage your IPB sites.";

		//-----------------------------------------
		// start table
		//-----------------------------------------

		$this->ipsclass->adskin->td_header[] = array( " "  , "2%" );
		$this->ipsclass->adskin->td_header[] = array( "Country name"  , "60%" );
		$this->ipsclass->adskin->td_header[] = array( "Action"  , "10%" );

		$basic_title = "<table cellpadding='0' cellspacing='0' border='0' width='100%'>
						<tr>
						 <td align='left' width='40%' style='font-size:12px; vertical-align:middle;font-weight:bold; color:#FFF;'>Sites management</td>
						</tr>
						</table>";

		$this->ipsclass->html .= $this->ipsclass->adskin->start_table($basic_title);

		//-----------------------------------------
		// Get categories
		//-----------------------------------------

		$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'location','where'=>'location_level=0'));
		$this->ipsclass->DB->simple_exec();

		while( $site = $this->ipsclass->DB->fetch_row() )
		{
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<div align='center'><img src='{$this->ipsclass->adskin->img_url}/images/settings_folder.gif' border='0' alt='Folder' /></div>",
																   "<a href='{$this->ipsclass->base_url}&{$this->ipsclass->form_code}&code=city_show&countryid={$site['location_id']}' title=''><b>{$site['location_name']}</b></a>" ,
												  				   array("<div align='center' style='white-space:nowrap'>
												  				          <a href='{$this->ipsclass->base_url}&{$this->ipsclass->form_code}&code=country_showedit&id={$site['location_id']}' title='Edit this country'><img src='{$this->ipsclass->adskin->img_url}/images/icons_menu/edit.gif' border='0' alt='Edit'  /></a>
																          <a href='{$this->ipsclass->base_url}&{$this->ipsclass->form_code}&code=location_delete&id={$site['location_id']}' title='Delete this location'><img src='{$this->ipsclass->adskin->img_url}/images/icons_menu/delete.gif' border='0' alt='Delete'  /></a>
																          </div>", 1, 'tablerow3' )
										 					  )      );
		}

		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		
		$this->ipsclass->admin->page_title  = "Location Management";
		$this->ipsclass->admin->page_detail = "This section contains all the functions to manage your IPB site.";
		$this->ipsclass->admin->nav[]       = array( '', "Add/Edit Site" );

		$forum_ids = array();
		$formcode = 'country_add';
		$title    = "Create New Country";
		$button   = "Add Site";
		$location = array( 	   'location_name' 		=> '',
						   'location_level' 	=> '',
						   'location_parent'	=> '',
						   );


		$this->ipsclass->admin->page_detail = '&nbsp;';
		$this->ipsclass->admin->page_title  = $title;

		
		//-----------------------------------------
		// start form
		//-----------------------------------------

		$this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'code'   , $formcode ),
																			 2 => array( 'act'    , 'locations'      ),
																			 3 => array( 'parent'     , 0 ),
																			 4 => array( 'level'     , 0 ),
																			 5 => array( 'section', 'content' ),
																	)      );

		//-----------------------------------------
		// start table
		//-----------------------------------------

		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "40%" );
		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "60%" );

		//-----------------------------------------
		// um..
		//-----------------------------------------

		$this->ipsclass->html .= $this->ipsclass->adskin->start_table( $title );
												 		    	
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Country Name</b><div style='color:gray'>Example: Việt Nam</div>" ,
												  			   $this->ipsclass->adskin->form_input( 'locationName' )
										 		    	)      );
		
		$this->ipsclass->html .= $this->ipsclass->adskin->end_form( $button );

		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();

		$this->ipsclass->admin->output();

	}
	
	function city_show($countryId=0){
		
		$countryId = $countryId?$countryId:$this->ipsclass->input['countryid'];
		$this->ipsclass->admin->page_title  = "Category management";
		$this->ipsclass->admin->page_detail = "This section contains all the functions to manage your IPB shop.";

		// Get category
		$this->ipsclass->DB->simple_construct(array('select'=> '*', 
													'from'	=> 'location',
													'where'	=> 'location_id='.$countryId
													));
		$this->ipsclass->DB->simple_exec();
		
		$category = $this->ipsclass->DB->fetch_row();
		
		//-----------------------------------------
		// start table
		//-----------------------------------------

		$this->ipsclass->adskin->td_header[] = array( " "  , "2%" );
		$this->ipsclass->adskin->td_header[] = array( "City name"  , "60%" );
		$this->ipsclass->adskin->td_header[] = array( "Action"  , "10%" );
		
		$basic_title = "<table cellpadding='0' cellspacing='0' border='0' width='100%'>
						<tr>
						 <td align='left' width='40%' style='font-size:12px; vertical-align:middle;font-weight:bold; color:#FFF;'>City in <u>{$category['location_name']}</u></td>
						 <td align='right' width='60%' style='padding-right: 10px'><input class='realbutton' onclick=\"self.location.href='{$this->ipsclass->base_url}&{$this->ipsclass->form_code}&code=city_new&countryid={$this->ipsclass->input['countryid']}'\" type='button' value='Add New City' /></td>
						</tr>
						</table>";

		$this->ipsclass->html .= $this->ipsclass->adskin->start_table($basic_title);

		//-----------------------------------------
		// Get categories
		//-----------------------------------------

		$this->ipsclass->DB->simple_construct( array('select' 	=> '*', 
													 'from' 	=> 'location',
													 'where'	=> 'location_parent='.$countryId,
													 'order'	=> 'location_name'
														));
		$this->ipsclass->DB->simple_exec();

		while( $item = $this->ipsclass->DB->fetch_row() )
		{
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<div align='center'><img src='{$this->ipsclass->adskin->img_url}/images/settings_folder.gif' border='0' alt='Folder' /></div>",
																    "<a href='{$this->ipsclass->base_url}&{$this->ipsclass->form_code}&code=district_view&cityid={$item['location_id']}' title='Click to view this district'><b>{$item['location_name']}</b></a>" ,
												  				   array("<div align='center' style='white-space:nowrap'>
												  				          <a href='{$this->ipsclass->base_url}&{$this->ipsclass->form_code}&code=city_showedit&id={$item['location_id']}' title='Edit this city'><img src='{$this->ipsclass->adskin->img_url}/images/icons_menu/edit.gif' border='0' alt='Edit'  /></a>
																          <a href='{$this->ipsclass->base_url}&{$this->ipsclass->form_code}&code=city_delete&id={$item['location_id']}&countryid={$item['location_parent']}' title='Delete this item'><img src='{$this->ipsclass->adskin->img_url}/images/icons_menu/delete.gif' border='0' alt='Delete'  /></a>
																          </div>", 1, 'tablerow3' )
										 					  )      );
		}

		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();

		$this->ipsclass->admin->output();
	}
		
	//-----------------------------------------
	//
	// City show form
	//
	//-----------------------------------------

	function city_form( $type='add' )
	{
		$this->ipsclass->admin->page_title  = "Location Management";
		$this->ipsclass->admin->page_detail = "This section contains all the functions to manage your IPB site.";
		$this->ipsclass->admin->nav[]       = array( '', "Add/Edit city" );

		if($type=="add"){
			$formcode = 'city_add';
			$title    = "Create New Location";
			$button   = "Add City";
			$location = array( 	   'location_name' 		=> '',
							   'location_level' 	=> '',
							   'location_parent'	=> $this->ipsclass->input['countryid'],
							   );
		}
		else{
			$location = $this->ipsclass->DB->simple_exec_query( array( 'select' => '*', 'from' => 'location', 'where' => 'location_id='.intval($this->ipsclass->input['id']) ) );

			if ( ! $location['location_id']) {
				$this->ipsclass->main_msg = "No ID was passed, please try again.";
				$this->country_form();
			}

			$formcode = 'city_edit';
			$title    = "Edit City <u>".$location['location_name']."</u>";
			$button   = "Edit Location";
		}

		

		$this->ipsclass->admin->page_detail = '&nbsp;';
		$this->ipsclass->admin->page_title  = $title;

		// Get categories
		$this->ipsclass->DB->simple_construct(array('select' => '*',
													'from'	 => 'location',
													'where'	 => 'location_level=0'
													));
		$this->ipsclass->DB->simple_exec();
		
		$country = array();
		while($category = $this->ipsclass->DB->fetch_row()) {
			$country[] = array($category['location_id'],$category['location_name']);
		}
		
		//-----------------------------------------
		// start form
		//-----------------------------------------

		$this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'code'   , $formcode ),
																			 2 => array( 'act'    , 'locations'      ),
																			 3 => array( 'id'     , $this->ipsclass->input['id'] ),
																			 4 => array( 'level'     , 1 ),
																			 5 => array( 'section', 'content' ),
																	)      );

		//-----------------------------------------
		// start table
		//-----------------------------------------

		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "40%" );
		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "60%" );

		//-----------------------------------------
		// um..
		//-----------------------------------------

		$this->ipsclass->html .= $this->ipsclass->adskin->start_table( $title );
		
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Country</b>" ,
												  			   $this->ipsclass->adskin->form_dropdown( 'countryid', $country, ( isset($_POST['countryid']) AND $_POST['countryid'] ) ? $_POST['countryid'] : $location['location_parent'] )
										 		    	)      );
												 		    	
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>City Name</b><div style='color:gray'>Example: Ho Chi Minh</div>" ,
												  			   $this->ipsclass->adskin->form_input( 'locationName', ( isset($_POST['locationName']) AND $_POST['locationName'] ) ? $_POST['locationName'] : $location['location_name'] )
										 		    	)      );
		
		$this->ipsclass->html .= $this->ipsclass->adskin->end_form( $button );

		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();

		$this->ipsclass->admin->output();

	}
	
	function city_save($input="countryid",$type='add')
	{
		//-----------------------------------------
		// INIT
		//-----------------------------------------

		$location_name = $this->ipsclass->input['locationName'];
		$location_parent = $this->ipsclass->input[$input];
		//-----------------------------------------
		// Check...
		//-----------------------------------------

		if ( ! $location_name )
		{
			$this->ipsclass->main_msg = "You must enter location name.";
			$this->city_show($location_parent);
			return;
		}
		
		
		$array = array( 'location_name' 		=> $location_name,
						'location_level' 		=> $this->ipsclass->input['level'],
						'location_parent' 		=> $location_parent,
					 );


		if ( $type == 'add' )
		{
			$this->ipsclass->DB->do_insert( 'location', $array );
			$this->ipsclass->main_msg = 'New location Added';
		}
		else
		{
			$this->ipsclass->DB->do_update( 'location', $array, 'location_id='.intval($this->ipsclass->input['id']) );
			$this->ipsclass->main_msg = 'New location Edited';
		}

	}
	
	function district_view($cityId=0){
		$cityId = $cityId?$cityId:$this->ipsclass->input['cityid'];
		$this->ipsclass->admin->page_title  = "Category management";
		$this->ipsclass->admin->page_detail = "This section contains all the functions to manage your IPB shop.";

		// Get category
		$this->ipsclass->DB->simple_construct(array('select'=> '*', 
													'from'	=> 'location',
													'where'	=> 'location_id='.$cityId
													));
		$this->ipsclass->DB->simple_exec();
		
		$category = $this->ipsclass->DB->fetch_row();
		
		//-----------------------------------------
		// start table
		//-----------------------------------------

		$this->ipsclass->adskin->td_header[] = array( " "  , "2%" );
		$this->ipsclass->adskin->td_header[] = array( "District name"  , "60%" );
		$this->ipsclass->adskin->td_header[] = array( "Action"  , "10%" );
		
		$basic_title = "<table cellpadding='0' cellspacing='0' border='0' width='100%'>
						<tr>
						 <td align='left' width='40%' style='font-size:12px; vertical-align:middle;font-weight:bold; color:#FFF;'>District in <u>{$category['location_name']}</u></td>
						 <td align='right' width='60%' style='padding-right: 10px'><input class='realbutton' onclick=\"self.location.href='{$this->ipsclass->base_url}&{$this->ipsclass->form_code}&code=district_new&cityid={$this->ipsclass->input['cityid']}&countryid={$category['location_parent']}'\" type='button' value='Add New District' /></td>
						</tr>
						</table>";

		$this->ipsclass->html .= $this->ipsclass->adskin->start_table($basic_title);

		//-----------------------------------------
		// Get categories
		//-----------------------------------------

		$this->ipsclass->DB->simple_construct( array('select' 	=> '*', 
													 'from' 	=> 'location',
													 'where'	=> 'location_parent='.$cityId,
													 'order'	=> 'location_name'
														));
		$this->ipsclass->DB->simple_exec();
		
		while( $item = $this->ipsclass->DB->fetch_row() )
		{
			$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<div align='center'><img src='{$this->ipsclass->adskin->img_url}/images/settings_folder.gif' border='0' alt='Folder' /></div>",
																    "<a href='{$this->ipsclass->base_url}&{$this->ipsclass->form_code}&code=district_showedit&id={$item['location_id']}&countryid={$category['location_parent']}' title='Click to view this district'><b>{$item['location_name']}</b></a>" ,
												  				   array("<div align='center' style='white-space:nowrap'>
												  				          <a href='{$this->ipsclass->base_url}&{$this->ipsclass->form_code}&code=district_showedit&id={$item['location_id']}&countryid={$category['location_parent']}' title='Edit this district'><img src='{$this->ipsclass->adskin->img_url}/images/icons_menu/edit.gif' border='0' alt='Edit'  /></a>
																          <a href='{$this->ipsclass->base_url}&{$this->ipsclass->form_code}&code=district_delete&id={$item['location_id']}&cityid={$item['location_parent']}' title='Delete this district'><img src='{$this->ipsclass->adskin->img_url}/images/icons_menu/delete.gif' border='0' alt='Delete'  /></a>
																          </div>", 1, 'tablerow3' )
										 					  )      );
		}

		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();

		$this->ipsclass->admin->output();
	}
	
	function district_form($type="add"){
		$this->ipsclass->admin->page_title  = "Location Management";
		$this->ipsclass->admin->page_detail = "This section contains all the functions to manage your IPB site.";
		$this->ipsclass->admin->nav[]       = array( '', "Add/Edit district" );

		
		if($type=="add"){
			$formcode = 'district_add';
			$title    = "Create New Location";
			$button   = "Add District";
			$location = array( 	   'location_name' 		=> '',
							   'location_level' 	=> '',
							   'location_parent'	=> $this->ipsclass->input['cityid'],
							   );
		}
		else{
			$location = $this->ipsclass->DB->simple_exec_query( array( 'select' => '*', 'from' => 'location', 'where' => 'location_id='.intval($this->ipsclass->input['id']) ) );

			if ( ! $location['location_id']) {
				$this->ipsclass->main_msg = "No ID was passed, please try again.";
				$this->country_form();
			}

			$formcode = 'district_edit';
			$title    = "Edit District <u>".$location['location_name']."</u>";
			$button   = "Edit Location";
		}

		

		$this->ipsclass->admin->page_detail = '&nbsp;';
		$this->ipsclass->admin->page_title  = $title;

		// Get categories
		$this->ipsclass->DB->simple_construct(array('select' => '*',
													'from'	 => 'location',
													'where'	 => 'location_level=1 and location_parent='.$this->ipsclass->input['countryid']
													));
		$this->ipsclass->DB->simple_exec();

		$country = array();
		while($category = $this->ipsclass->DB->fetch_row()) {
			$country[] = array($category['location_id'],$category['location_name']);
		}
		
		//-----------------------------------------
		// start form
		//-----------------------------------------
		$this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'code'   , $formcode ),
																			 2 => array( 'act'    , 'locations'      ),
																			 3 => array( 'id'     , $this->ipsclass->input['id'] ),
																			 4 => array( 'level'     , 2 ),
																			 5 => array( 'section', 'content' ),
																	)      );

		//-----------------------------------------
		// start table
		//-----------------------------------------

		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "40%" );
		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "60%" );

		//-----------------------------------------
		// um..
		//-----------------------------------------

		$this->ipsclass->html .= $this->ipsclass->adskin->start_table( $title );
		
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>Country</b>" ,
												  			   $this->ipsclass->adskin->form_dropdown( 'cityid', $country, ( isset($_POST['cityid']) AND $_POST['cityid'] ) ? $_POST['cityid'] : $location['location_parent'] )
										 		    	)      );
												 		    	
		$this->ipsclass->html .= $this->ipsclass->adskin->add_td_row( array( "<b>City Name</b><div style='color:gray'>Example: Quận 1</div>" ,
												  			   $this->ipsclass->adskin->form_input( 'locationName', ( isset($_POST['locationName']) AND $_POST['locationName'] ) ? $_POST['locationName'] : $location['location_name'] )
										 		    	)      );
		
		$this->ipsclass->html .= $this->ipsclass->adskin->end_form( $button );

		$this->ipsclass->html .= $this->ipsclass->adskin->end_table();
		
		$this->ipsclass->admin->output();
	}
}

?>